package com.jt.www.hadoopcould.util;

import com.jt.www.hadoopcould.model.user;

import javax.servlet.*;
import javax.servlet.annotation.WebFilter;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;


@WebFilter(filterName = "HadoopFilterUtil",urlPatterns = "/*")
public class HadoopFilterUtil implements Filter {


    @Override
    public void init(FilterConfig filterConfig) throws ServletException {
        System.out.println(
                "初始化成功"
        );
    }

    @Override
    public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain) throws IOException, ServletException {
        System.out.println("过滤器");
        HttpServletRequest request=(HttpServletRequest)servletRequest;
        HttpServletResponse response=(HttpServletResponse)servletResponse;
        user user=(user) request.getSession().getAttribute("user");
        String s=request.getRequestURI();
        if (null!=user |s.equals("/loginmgr")|equals("/registr")|equals("/registrmgr")){
            filterChain.doFilter(request,response);

        }else{
            request.getRequestDispatcher("login").forward(request,response);
        }
    }

    @Override
    public void destroy() {
        System.out.println("销毁成功");
    }
}
